<!doctype html>
<html><head><meta charset="utf-8">
<title>lib/ccv_cache.c</title>
<link rel="stylesheet" href="/stylesheets/styles.css">
<link rel="stylesheet" href="/stylesheets/coderay.css">
<script src="/javascripts/scale.fix.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-303081-6']);
_gaq.push(['_trackPageview']);
(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head><body><div class="wrapper">
<header><h1><a href="/">ccv</a></h1>
<p>A Modern Computer Vision Library</p>
<p class="view"><a href="https://github.com/liuliu/ccv">View the Project on GitHub <small>liuliu/ccv</small></a></p>
<ul>
<li><a href="https://github.com/liuliu/ccv/zipball/stable">Download <strong>ZIP File</strong></a></li>
<li><a href="https://github.com/liuliu/ccv/tarball/stable">Download <strong>TAR Ball</strong></a></li>
<li><a href="https://github.com/liuliu/ccv">Fork On <strong>GitHub</strong></a></li>
</ul>
</header>
<section><h1>lib/ccv_cache.c</h1>
<p>This class implements a trie-based lru cache that is then used for ccv application-wide cache in <a href="/lib/ccv-memory">ccv_memory.c</a>.</p>

<h2 id="ccvcacheinit">ccv_cache_init</h2>

<pre><code>void ccv_cache_init(ccv_cache_t *cache, size_t up, int cache_types, ccv_cache_index_free_f ffree,...)
</code></pre>

<p>Setup a cache strcture to work with.</p>

<ul>
  <li><strong>cache</strong>: The allocated cache.</li>
  <li><strong>up</strong>: The upper limit of cache size in bytes.</li>
  <li><strong>cache_types</strong>: The number of cache types in this one cache instance.</li>
  <li><strong>ffree</strong>: The function that will be used to free cached object.</li>
</ul>

<h2 id="ccvcacheget">ccv_cache_get</h2>

<pre><code>void* ccv_cache_get(ccv_cache_t *cache, uint64_t sign, uint8_t *type)
</code></pre>

<p>Get an object from cache for its signature. 0 if cannot find the object.</p>

<ul>
  <li><strong>cache</strong>: The cache.</li>
  <li><strong>sign</strong>: The signature.</li>
  <li><strong>type</strong>: The type of the object.</li>
</ul>

<p><strong>return</strong>: The pointer to the object.</p>

<h2 id="ccvcacheput">ccv_cache_put</h2>

<pre><code>int ccv_cache_put(ccv_cache_t *cache, uint64_t sign, void *x, uint32_t size, uint8_t type)
</code></pre>

<p>Put an object to cache with its signature, size, and type</p>

<ul>
  <li><strong>cache</strong>: The cache.</li>
  <li><strong>sign</strong>: The signature.</li>
  <li><strong>x</strong>: The pointer to the object.</li>
  <li><strong>size</strong>: The size of the object.</li>
  <li><strong>type</strong>: The type of the object.</li>
</ul>

<p><strong>return</strong>: 0 - success, 1 - replace, -1 - failure.</p>

<h2 id="ccvcacheout">ccv_cache_out</h2>

<pre><code>void* ccv_cache_out(ccv_cache_t *cache, uint64_t sign, uint8_t *type)
</code></pre>

<p>Get an object from cache for its signature and then remove that object from the cache. 0 if cannot find the object.</p>

<ul>
  <li><strong>cache</strong>: The cache.</li>
  <li><strong>sign</strong>: The signature.</li>
  <li><strong>type</strong>: The type of the object.</li>
</ul>

<p><strong>return</strong>: The pointer to the object.</p>

<h2 id="ccvcachedelete">ccv_cache_delete</h2>

<pre><code>int ccv_cache_delete(ccv_cache_t *cache, uint64_t sign)
</code></pre>

<p>Delete an object from cache for its signature and free it.</p>

<ul>
  <li><strong>cache</strong>: The cache.</li>
  <li><strong>sign</strong>: The signature.</li>
</ul>

<p><strong>return</strong>: -1 if cannot find the object, otherwise return 0.</p>

<h2 id="ccvcachecleanup">ccv_cache_cleanup</h2>

<pre><code>void ccv_cache_cleanup(ccv_cache_t *cache)
</code></pre>

<p>Clean up the cache, free all objects inside and other memory space occupied.</p>

<ul>
  <li><strong>cache</strong>: The cache.</li>
</ul>

<h2 id="ccvcacheclose">ccv_cache_close</h2>

<pre><code>void ccv_cache_close(ccv_cache_t *cache)
</code></pre>

<p>For current implementation (trie-based LRU cache), it is an alias for ccv_cache_cleanup.</p>

<ul>
  <li><strong>cache</strong>: The cache.</li>
</ul>

<h3><a href="/">&lsaquo;&nbsp;&nbsp;back&nbsp;</a></h3>
<div id="disqus_thread"></div>
<script type="text/javascript">
	var disqus_shortname = 'libccv';
	(function() {
		var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
		dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
	})();
</script>
<a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>

</section>
<footer>
<p>This project is maintained by <a href="https://liuliu.me/">liuliu</a></p>
<p><small>Theme originated from <a href="https://github.com/orderedlist">orderedlist</a></small></p>
</footer>
</div>
<!--[if !IE]><script>fixScale(document);</script><!--<![endif]-->
</body>
</html>
